﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
using System.IO;
using System.Drawing;

namespace BattleThis.Helpers
{
	/// <summary>
	/// Template-Object to create colored Instance of a Svg-File.
	/// </summary>
	/// <remarks>
	/// Replace the color #FF00FF to make dyed copies.
	/// </remarks>
	public class SvgColorTemplate
	{
		#region Variablen
		private static readonly Regex TemplateColorRegex = new Regex( "#ff00ff" );
		#endregion

		#region Properties

		/// <summary>
		/// Get the FileInfo-Object from them template-file.
		/// </summary>
		public FileSystemInfo FileInfo { get; protected set; }

		#endregion

		#region Methode
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="fullFileName">Full file path to the template-file e.g. </param>
		public SvgColorTemplate( string fullFileName )
		{
			this.FileInfo = new FileInfo( fullFileName );
		}

		/// <summary>
		/// Create a Dyed TemplateResult that can be saved.
		/// </summary>
		/// <param name="newColor">Color to dyed.</param>
		/// <returns></returns>
		public SvgColorTemplateResult Dyed( Color newColor )
		{
			StreamReader streamReader = new StreamReader( this.FileInfo.FullName );
			string text = streamReader.ReadToEnd();
			streamReader.Close();

			var newFile = SvgColorTemplate.TemplateColorRegex.Replace( text, newColor.ToHex() );
			var result = new SvgColorTemplateResult( newFile, newColor );

			return result;
		}
		#endregion
	}
}